package com.machang.designpattern.umlrelation;

import javax.swing.plaf.synth.SynthSeparatorUI;

/**
 * UML常见关系
 * @Auther MaChang
 * @Date 2022-01-09 23:42
 */
public class UmlRelations {

}
//1.继承关系 Generalization
class Car1{
    private String name;
    public void run(){}
}

class Bus extends Car1{

}

class Taxi extends Car1{

}

//2.实现关系 Realization
interface Vehicle{
    void run();
}

class Car2 implements Vehicle{
    @Override
    public void run() {
        System.out.println("汽车");
    }
}

class Ship implements Vehicle{
    @Override
    public void run() {
        System.out.println("船");
    }
}

//3.组合关系 Combination  (同生死，共存亡）
class Head{
    private String name;
}

class Body{
    private String name;
}

class Human{
    private Head head;
    private Body body;

    public void setHead(Head head) {
        this.head = head;
    }

    public void setBody(Body body) {
        this.body = body;
    }
}

//4.聚合关系 Aggregate （部分可以单独存在，没有共同生命周期）
class Hat{
    private String name;
}
class Clothes{
    private String name;
}

class BusDriver{
    private Hat hat;
    private Clothes clothes;

    public void setClothes(Clothes clothes) {
        this.clothes = clothes;
    }

    public void setHat(Hat hat) {
        this.hat = hat;
    }

    public void show(){
        
    }
}

//5.关联关系 Association 组合，聚合也属于关联关系
//关联关系有4中，双向关联，单向关联，自关联，多重关联
//例子
class Driver{
    private Car3 car;    
}

class Car3{
    private Driver driver;
}

//5.依赖关系 Dependency 使用
class Oil{

}

class Car4{
    
    public void beforeRun(Oil oil){
        System.out.println("先加油");
    }
}